import { WEBAPP_MAIN_USERINFO } from "@/store/userInfo";

/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default (value) => {
  if (value && value instanceof Array && value.length > 0) {
    const WEBAPP_MAIN_USERINFOSTORE = WEBAPP_MAIN_USERINFO();
    const roles = WEBAPP_MAIN_USERINFOSTORE.roles;
    const permissionRoles = value;
    return roles.some((role: any) => {
      return permissionRoles.includes(role);
    });
  } else {
    console.error(`need roles! Like v-permission="['admin','editor']"`);
    return false;
  }
};
